package com.webex.ta.hydra.gui.menu;

import com.webex.ta.hydra.gui.MenuFactory;
import com.webex.ta.hydra.gui.GuiPackage;
import com.webex.ta.hydra.gui.table.HydraTable;
import com.webex.ta.hydra.gui.action.ActionNames;
import com.webex.ta.hydra.gui.action.KeyStrokes;
import com.webex.ta.hydra.util.HydraUtils;

import javax.swing.*;

/**
 * Author: Vegaz
 * Date: 2010-11-9
 * Time: 10:03:22
 */
public class EditMenuProvider implements DynamicMenuProvider {
    private ContextMenuProvider contextProvider = new ContextMenuProvider();

    public void update(JMenu menu) {
        JMenuItem edit_undo = MenuFactory.makeMenuItem("Undo", 'U', "Undo", ActionNames.UNDO, KeyStrokes.UNDO);
        edit_undo.setIcon(HydraUtils.getImage("undo.gif"));
        JMenuItem edit_redo = MenuFactory.makeMenuItem("Redo", 'R', "Redo", ActionNames.REDO, KeyStrokes.REDO);
        edit_redo.setIcon(HydraUtils.getImage("redo.gif"));

        HydraTable table = GuiPackage.getInstance().getHydraTable();
        if (table != null) {
            edit_undo.setEnabled(table.canUndo());
            edit_redo.setEnabled(table.canRedo());
        } else {
            edit_undo.setEnabled(false);
            edit_redo.setEnabled(false);
        }
        
        menu.add(edit_undo);
        menu.add(edit_redo);
        menu.addSeparator();
        contextProvider.update(menu);
    }

    public boolean updateEveryTime() {
        return true;
    }
}
